n, m, q = map(int, input().split())

graph = [[float('inf') for _ in range(n + 1)] for _ in range(n + 1)]
plans = []
for _ in range(m):
    u, v, w = map(int, input().split())
    graph[u][v] = w

for i in range(n + 1):
    graph[i][i] = 0
for midd in range(1, n + 1):
    for start in range(1, n + 1):
        for end in range(1, n + 1):
            graph[start][end] = min(graph[start][midd] + graph[midd][end], graph[start][end])

for _ in range(q):
    u, v = map(int, input().split())
    o = graph[u][v]
    if o != float('inf'):
        print(o)
    else:
        print(-1)
